var category = [];
var map1List = [];
var output_value = new Array(3);
var barData = [];
var address, year;

var url = location.search; //获取url中"?"符后的字串
if (url.indexOf("?") != -1) {
    address = decodeURI(url.substr(1).split("=")[1].split("?")[0]);
    year = decodeURI(url.substr(1).split("=")[2]);
}

$.ajax({
    type: "post",
    async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
    url: "ZhejiangGDPServlet?address=" + address + "&year=" + year,    //请求发送到TestServlet处
    data: {},
    dataType: "json",
    //返回数据形式为json
    success: function (result) {
        //请求成功时执行该函数内容，result即为服务器返回的json对象
        if (result) {
            var json = eval(result);
            for (var i = 0; i < json.length; i++) {
                var type = json[i].type;
                if (type != "第一产业" && type != "第二产业" && type != "第三产业" && type != "﻿生产总值") {
                    category.push(type);
                    barData.push(json[i].value);
                }
                if (type == "第一产业") {
                    output_value[0] = json[i].value;
                }
                if (type == "第二产业") {
                    output_value[1] = json[i].value;
                }
                if (type == "第三产业") {
                    output_value[2] = json[i].value;
                }
            }

            for (var i = 0; i < barData.length; i++) {
                for (var j = 0; j < barData.length - 1; j++) {
                    if (barData[j] < barData[j + 1]) {
                        var t = barData[j];
                        barData[j] = barData[j + 1];
                        barData[j + 1] = t;
                        var k = category[j];
                        category[j] = category[j + 1];
                        category[j + 1] = k;
                    }
                }
            }

            var lastSum = 0;
            for (var i = 0; i < barData.length; i++) {
                if (map1List.length < 9) {
                    map1List.push({
                        //通过把result进行遍历循环来获取数据并放入Echarts中
                        name: category[i],
                        value: barData[i]
                    });
                }

                else {
                    lastSum = lastSum + barData[i];
                }
            }
            map1List.push({
                //通过把result进行遍历循环来获取数据并放入Echarts中
                name: "其他",
                value: lastSum
            });
        }
    }
})
